<?php
ini_set('display_errors',0);
set_time_limit(0);
//exit();

$s = microtime(true);
/**
 * date : 2012-2-13
 * 抓取
 * 友情链接网上IT类的QQ
 * www.tuicao.com
 * 
 * 抓取网站的rp值在1以上
 * 
 * 存到当前目录的link.txt
 */
$fp = fopen("link.txt", "a");
for($i=1;$i<=3949;$i++){
	$output = get_url("http://www.tuicao.com/Default.aspx?page={$i}&wt=&wl=&wp=&wz=&wbai=&wgg=");
	//取得想要的数据放到$out[1]
	preg_match('/Label_bind(.+)vod_message_pager/is',$output,$out);
	preg_match_all('/<tr id=(.+?)<\/tr>/s',$out[1],$arr);
	
	$str = null;
	foreach ($arr[1] as $value) {
		preg_match('/images\/pa.gif\\\'">(.+)<\/a>/is',$value,$qq);
		if(is_numeric($qq[1]))
			$str .= trim($qq[1])."@qq.com\r\n";
		
	}
	echo $str;
	fwrite($fp, $str);
}

$time_sum = number_format(microtime(true) - $s, 3, '.', '');
echo "耗时:{$time_sum}秒,".($time_sum/60)."分,".($time_sum/3600)."小时";

function get_url($u){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $u);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_POST, 1);
	$output = curl_exec($ch);
	curl_close($ch);
	return $output;
}
